<template>
	<view>
		<view class="comlog">
			<view class="logos">
				<image class="logoimg" src="../../../static/logo.png" mode="widthFix"></image>
			</view>
			<text class="wclz t-c m-t5">高校思政教育教学中心</text>
			<!-- <text class="wcl t-c m-t4">版本V1.001</text> -->
			<text class="wcl t-c m-t3">南京德教思政科技有限公司</text>
			<view class="sign">
				<view class="sign_t">
					<text class="wc-l1 m-l2">账号：</text>
					<input type="text" placeholder-style="font-size:24upx;" placeholder="使用手机/学号/编号登录" v-model="unsername" class="sign_r m-t1">
				</view>
				<view class="sign_t m-t2">
					<text class="wc-l1 m-l2">密码：</text>
					<input type="text" placeholder-style="font-size:24upx;" password="true" v-model="password" placeholder="请输入密码" class="sign_r m-t1">
				</view>
				<picker mode="selector" :range="ips" range-key="name" @change="bindCol">
					<button type="warn" class="wcl m-t7" style="margin-top: 20upx;" >选择校区</button>
					<view style="text-align: center;margin-top: 10upx;font-size: 26upx;">{{colName}}</view>
				</picker>
				<button type="warn" class="wcl m-t7" @click="tz" style="margin-top: 20upx;">登录</button>
				<view class="wcl m-t7" @click="toForgetPwd()" style="margin-top: 20upx;cursor:pointer;color: #007AFF;text-decoration:underline;padding: 20upx;">忘记密码</view>
				<view v-if="isRegesiter == 1" class="wcl m-t7" @click="register()" style="margin-top: 0upx;cursor:pointer;color: #007AFF;text-decoration:underline;padding: 20upx;">注册账号</view>
				<!-- <button type="warn" class="wcl m-t7" @click="tz2" style="margin-top: 20upx;">选择校区</button> -->
				
			</view>
			<view class="wcl m-t7" style="margin-left:50upx;">
				<checkbox style="transform: scale(0.7);padding:10upx;" @click="isCheckChange"></checkbox>
				我已阅读并同意
			<span style="color: #007AFF;text-decoration:underline" @click="toZhengce()">《隐私政策》</span>和
			<span style="color: #007AFF;text-decoration:underline" @click="toXieyi()">《用户协议》</span>
			</view>
			
			<view class="logo_bottom">
				<text class="hx"></text>
				<text class="wc-l1 w-ywh">用户登录</text>
				<text class="hx"></text>
			</view>
		</view>
<!-- 		<view class="style11x" v-if="isShowWarn">
		  <view class="style16x">
		    <view class="style12x"> 服务协议和隐私政策 </view>
		    <view class="style13x">
		      请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款，包括但不限于：为了向你提供即时通讯、内容分享等服务，我们需要收集你的设备信息、操作日志等个人信。你可以在“设置”中查看、变更、删除个人信息理你的授权。<br />你可阅读<span
		        @click="toXieyi"
		        >《用户协议》</span
		      >和<span @click="toZhengce">《私政政策》</span
		      >了解详细信息。如你同意，请点击“同意”开始接受我们的服务。
		    </view>
		    <view class="style14x" @click="wranNO">暂不使用</view>
		    <view class="style15x" @click="wranOK">同意</view>
		  </view>
		</view> -->
	</view>
</template>

<script>
	export default{
		data(){
			return{
				token:'',
				unsername:'',
				password:'',
				ips:[],
				colName:'',
				isRegesiter:1,
				isCheck:false,
				isShowWarn:false,
			}
		},
		onShow(){
			// this.token = uni.getStorageSync('token')
			// if(this.token == ''){
			// 	return;
			// }else{
			// 	uni.switchTab({
			// 		url:'/pages/index/index'
			// 	})
			// }
			this.showWran();
		},
		methods:{
			//弹出提示，同意使用本软件
			showWran() {
			  let isUsed = uni.getStorageSync("isUsed");
			  let that = this;
			  if (!isUsed) {
			    that.isShowWarn = true;
			  } else {
			    that.isShowWarn = false;
			  }
			},
			//同意协议
			wranOK() {
			  uni.setStorageSync("isUsed", true);
			  this.isShowWarn = false;
			},
			//不同意协议
			wranNO() {
			  //退出程序
			  if (plus.os.name == "iOS") {
			    const threadClass = plus.ios.importClass("NSThread");
			    const mainThread = plus.ios.invoke(threadClass, "mainThread");
			    plus.ios.invoke(mainThread, "exit");
			    plus.ios
			      .import("UIApplication")
			      .sharedApplication()
			      .performSelector("exit");
			  } else if (plus.os.name == "Android") {
			    plus.runtime.quit();
			  }
			},
			toZhengce(){
				uni.navigateTo({
					url: './zhengce'
				})
			},
			toXieyi(){
				uni.navigateTo({
					url: './xieyi'
				})
			},
			toForgetPwd(){
				if(!this.colName){
					this.toast("请先选择校区");
					return;
				}
				uni.navigateTo({
					url: './forgetpwd'
				})
			},
			register(){
				if(!this.colName){
					this.toast("请先选择校区");
					return;
				}
				uni.navigateTo({
					url: 'register',
				})
			},
			getIPs(){
				let that = this;
				that.pyReq(that.$http.taskQuaGetColInfo,{},function(res){
					that.ips = res.result;
					console.log(res);
				});
			},
			getRegesiter(){
				let that = this;
				that.pyReq(that.$http.isRegesiter,{},function(res){
					that.isRegesiter = res.result;
				});
			},
			bindCol(e){
				this.colName = this.ips[e.detail.value].name;
				uni.setStorageSync('baseUrl',this.ips[e.detail.value].ip);
			},
			isCheckChange(){
				let that = this;
				that.isCheck = !that.isCheck;
			},
			tz(){
				let that = this
				// if(!that.colName){
				// 	that.toast('先选择校区');
				// 	return;
				// }
				if(that.unsername === '' || that.password === ''){
					uni.showToast({
						icon:"none",
						title:"账号密码不能为空"
					})
				}else{
					let params = {
					  "username":that.unsername,
					  "password":that.password
					}
					if(that.isCheck==false){
						uni.showToast({
							icon:"none",
							title:"请勾选同意后再登录"
						})
						return;
					}
					that.pyReq(that.$http.login,params,function(res){
						console.log(res);
						uni.setStorageSync('token',res.result.token)
						uni.setStorageSync('cokei',res.result.role)
						console.log(res.result.isNewPwd);
						if(res.result.isNewPwd == 0){
							that.toast("当前密码为默认密码，请先修改密码");
							setTimeout(function(){
								uni.reLaunch({
									url:'/pages/index/logo/logosj'
								})
							},1500)
						}else{
								uni.reLaunch({
									url:'/pages/index/index'
								})
						}
					});
					
				}
			},
			
		},
		created() {
			// console.log(this.$http.login)
			this.getIPs();
			this.getRegesiter();
		}
		
	}
</script>

<style>
	.sign_t{
		position: relative;
	}
	.sign_t input::-webkit-input-placeholder{
		font-size: 14upx;
	}
	.verification{
		position: absolute;
		right: 0;
		top: 10upx;
		font-size: 15upx;
		color: #BA2B26;
		width: 159upx;
		height: 50upx;
		line-height: 44upx;
		padding: 0;
		background: none;
		border:1upx #BA2B26 solid;
		border-radius: 30upx;
	}
	.comlog{
		width: 100%;
	}
	.logos{
		width: 162upx;
		height: 224upx;
		/* border: 1upx dashed #333333; */
		margin: 0 auto;
		margin-top: 130upx;
	}
	.logoimg{
		width: 162upx;
		display: block;
	}
	.t-c{
		display: block;
	}
	.sign{
		width: 420upx;
		margin: 0 auto;
		margin-top: 100upx;
	}
	.sign_t{
		border-radius:10upx;
		border: 1upx solid #AEAEAE;
		display: flex;
		height: 66upx;
	}
	.wc-l1{
		width: 130upx;
		color: #969696;
		line-height: 66upx;
		font-size: 24upx;
	}
	.sign_r{
		width: 500upx;
		font-size: 24upx;
		margin-top: 16upx;
	}
	.logo_bottom{
		width: 420upx;
		margin: 0 auto;
		margin-top: 100upx;
		display: flex;
		justify-content: space-between;
	}
	.w-ywh{
		text-align: center;
	}
	.hx{
		width: 140upx;
		height: 2upx;
		background-color: #E0E0E0;
		margin-top: 35upx;
	}
	.style11x {
	  position: fixed;
	  top: 0;
	  left: 0;
	  width: 100%;
	  height: 100vh;
	  background-color: rgba(0, 0, 0, 0.5);
	  z-index: 99999;
	}
	.style16x {
	  margin-top: 25vh;
	  background-color: #fff;
	  width: 80vw;
	  margin-left: auto;
	  margin-right: auto;
	  border-radius: 10upx;
	  overflow: hidden;
	}
	.style12x {
	  font-size: 34upx;
	  color: #333;
	  padding: 40upx 0upx 20upx 0;
	  text-align: center;
	}
	.style13x {
	  font-size: 28upx;
	  color: #333;
	  padding: 14upx 50upx;
	  line-height: 40upx;
	}
	.style13x span {
	  color: #447cf5;
	}
	.style14x {
	  font-size: 30upx;
	  float: left;
	  color: #333;
	  width: 40vw;
	  text-align: center;
	  padding: 20upx 0 40upx 0;
	}
	.style15x {
	  font-size: 30upx;
	  float: left;
	  color: #447cf5;
	  width: 40vw;
	  text-align: center;
	  padding: 20upx 0 40upx 0;
	}
</style>
